package edu.msg.jthr.backend.bean;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import edu.msg.jthr.backend.exception.ServiceException;
import edu.msg.jthr.backend.model.Interview;
import edu.msg.jthr.backend.repository.exception.RepositoryException;
import edu.msg.jthr.backend.repository.service.InterviewRepository;
import edu.msg.jthr.backend.service.InterviewService;

@Stateless(name = "InterviewServiceBean", mappedName = "ejb/InterviewServiceBean")
public class InterviewServiceBean implements InterviewService {
	@EJB
	private InterviewRepository interviewRepository;
	private static Logger LOG = LoggerFactory
			.getLogger(CandidateServiceBean.class);

	@Override
	public List<Interview> getAll() throws ServiceException {
		try {
			return interviewRepository.getAll();
		} catch (RepositoryException e) {
			LOG.error("Get all interviews error! + e.getMessage()");
			throw new ServiceException("Candidate getById error!", e);
		}
	}

	@Override
	public Interview getById(Long id) throws ServiceException {
		try {
			return interviewRepository.getById(id);
		} catch (RepositoryException e) {
			LOG.error("Interview getById error! + e.getMessage()");
			throw new ServiceException("Candidate getById error!", e);
		}
	}

	@Override
	public void create(Interview obj) throws ServiceException {
		try {
			interviewRepository.create(obj);
		} catch (RepositoryException e) {
			LOG.error("Interview persist error! + e.getMessage()");
			throw new ServiceException("Candidate getById error!", e);
		}
	}

	@Override
	public void delete(Interview obj) throws ServiceException {
		try {
			interviewRepository.delete(obj);
		} catch (RepositoryException e) {
			LOG.error("Interview delete error! + e.getMessage()");
			throw new ServiceException("Candidate getById error!", e);
		}

	}

	@Override
	public Interview update(Interview obj) throws ServiceException {
		try {
			return interviewRepository.update(obj);
		} catch (RepositoryException e) {
			LOG.error("Interview update error! + e.getMessage()");
			throw new ServiceException("Candidate getById error!", e);
		}

	}

}
